package com.amigo.online.provider.compare.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.amigo.online.provider.common.entity.UserMysqlInfo;
import com.amigo.online.provider.common.entity.UserSolrInfo;
import com.amigo.online.provider.sync.convert.model.VideoUserBO;

@Mapper
@Component
public interface UserComparisonMapper {

    @Select("select id from user_tbl order by id  desc limit 1")
    Integer getMaxId();

    @Select("select id, nickname from user_tbl where id >= ${startId} and id <= #{endId}")
    List<UserMysqlInfo> listfindByStartIdAndEndId(@Param("startId") int startId, @Param("endId") int endId);

    @Select("select id, nickname from user_tbl where id >= ${startId} and id <= #{endId}")
    List<UserSolrInfo> listfindByStartIdAndEndIdForSolr(@Param("startId") int startId, @Param("endId") int endId);

    @Select("select avatar, nickname from user_tbl where id = #{userId}")
    VideoUserBO findVideoUserInfoByUserId(@Param("userId") long userId);

    @Select("SELECT t1.id FROM user_tbl t1"
            + " JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM user_tbl)-(SELECT MIN(id) FROM user_tbl))+(SELECT MIN(id) FROM user_tbl)) AS id) AS t2"
            + " WHERE t1.id >= t2.id ORDER BY t1.id LIMIT #{number}")
    List<UserMysqlInfo> listUserInfoWithNumber(@Param("number") int randomComparsionNumber);
}
